# coding=utf-8
from flask import request
from flask.blueprints import Blueprint
from src.response.LayR import LayR
from src.service.userservice import get_user_list, del_user_by_id, add_user_service, update_user_service

user_api = Blueprint('userapi', __name__, url_prefix="/api/user")


@user_api.route("/get", methods=["POST"])
def get_user():
    limit = int(request.form.get("limit"))
    page = int(request.form.get("page"))
    username = request.form.get("username")
    return get_user_list(limit=limit, page=page, username=username)


@user_api.route("/del", methods=["POST"])
def del_user():
    user_id = request.form.get("id")
    return del_user_by_id(id=user_id)


@user_api.route("/add", methods=["POST"])
def add_user():
    uname = request.form.get("uname")
    email = request.form.get("email")
    content = request.form.get("content")
    password = request.form.get("password")
    return add_user_service(uname=uname, email=email, content=content,password=password)


@user_api.route("/update", methods=["POST"])
def update_user():
    uname = request.form.get("uname")
    email = request.form.get("email")
    content = request.form.get("content")
    password = request.form.get("password")
    uid = request.form.get("id")
    return update_user_service(uname=uname, email=email, content=content,password=password, uid=uid)
